package com.leet.code.lcof;

public class Code11 {
    public static void main(String[] args) {
        int[] numbers = {3, 1};
        System.out.println(minArray(numbers));
    }

    public static int minArray(int[] numbers) {

        if (numbers.length == 1) {
            return numbers[0];
        }
        int start = 0, end = numbers.length - 1;
        if (numbers[start] < numbers[end]) {
            return numbers[start];
        }

        int middle;

        while (start < end) {
            middle = start + (end - start) / 2;

            if (numbers[middle] < numbers[end]) {
                end = middle;
            } else if (numbers[middle] > numbers[end]) {
                start = middle + 1;
            } else {
                end = end - 1;
            }

        }

        return numbers[start];


    }


}
